package com.lhy.ltss.controller;

import com.alibaba.fastjson.JSONObject;
import com.lhy.ltss.common.UserRoleConst;
import com.lhy.ltss.service.FinderService;
import com.lhy.ltss.tag.HasRole;
import com.lhy.ltss.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * 找书员的相关操作
 * @author: 李汇远
 */
@RestController
@RequestMapping("finder")
public class FinderController {

    @Autowired
    FinderService finderService;

    /**
     * 找书员获取自己的订单
     * @return
     */
    @GetMapping
    @HasRole(UserRoleConst.FINDER)
    public JSONObject getOrder(String bookIndex){
        return ResultJson.ok(finderService.getOrder(bookIndex));
    }

    /**
     * 找书员找到图书，更改订单详情状态，并检查主订单的订单详情是否全部处理
     * @param id
     * @return
     */
    @PutMapping
    @HasRole(UserRoleConst.FINDER)
    public JSONObject updateStatus(Integer id, String res){
        finderService.updateStatus(id, res);
        return ResultJson.ok("操作成功");
    }

}
